from base_config.config import config
from base_config.log_config import create_logs
# 创建目录
create_logs()

Q_CLUSTER = {
    "name": "DjangoQCluster",
    "workers": 4,  # 工作线程数
    "recycle": 500,  # 每500次任务重启工作进程
    "timeout": 60,  # 任务超时时间（秒）
    "compress": True,  # 压缩任务结果
    "save_limit": 250,  # 保留最近250个任务结果
    "queue_limit": 500,  # 队列最大任务数
    "cpu_affinity": 1,  # 每个工作进程绑定的CPU核心数
    "label": "Django Q",
    "hook": "q_scheduler.init_scheduler.register_fixed_schedules",  # 启动固定周期任务
    "redis": {  # 配置redis
        "host": config.redis.host,
        "port": config.redis.port,
        "db": 1,
        "password": config.redis.password,
        "socket_timeout": None,
        "charset": "utf-8",
        "errors": "strict",
        "unix_socket_path": None,
    },
}

"""
1、迁移命令：
    python manage.py migrate django_q
2、启动命令：
    python manage.py qcluster
3、配置: settings
from q_scheduler.config import Q_CLUSTER
Q_CLUSTER = Q_CLUSTER

4、注册app

INSTALLED_APPS = [
    "q_scheduler.apps.QSchedulerConfig",# 覆盖django-q的启动命令(python manage.py qcluster)
    "django_q",  # 定时任务处理,数据库迁移，启动命令
]
"""